#打印购物小条，内容为物品名、花费金额、总金额
#定义购物函数，返回购物小条



#购物函数
def shopping(list1,num,dictionary1):
    money1 = num
    commodity1 = dictionary1
    shopping_trolley1 = list1
    commodity2 = {}
    sum1 = 0  #计算总价格
    money2 = num  #剩余金额
    for item in shopping_trolley1:
        if item in commodity1:
            print(f"商场里有{item}这个商品")
            if commodity1[item] <= money1:
                sum1 += commodity1[item]
                money1 -= commodity1[item]  #扣钱
                print(f"{item}购买成功！")
                commodity2[item] = commodity1[item]
            else:
                print(f"{item}购买失败，穷鬼，钱不够！请到其它超市购买！")
                break
        else:
            print(f"没有{item}这个商品，别瞎弄！")

    commodity2["总金额"] = sum1
    return commodity2, money1

money = 5000
commodity = {
    "car":500,
    "house":1000
}
# shopping_trolley= ["car","house"]  #购物车
# a = shopping(shopping_trolley,money,commodity)
# print(f"购物小条:{a}")
i = 'o'
while i != 'q':
    print("请输入要购买的商品，以空格为分隔:")
    str_1 = input()
    shopping_trolley1 = str_1.split(" ")
    a = shopping(shopping_trolley1,money,commodity)
    print(a[0])
    money = a[1]
    print(f"余额：{money}")
    print("是否继续购物？\n任意键继续\nq退出")
    i = input()












